{#
    cdap/globaltoc.html
    ~~~~~~~~~~~~~~~~~~~

    Code to control sidebar table-of-contents.

    :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
    :copyright: Copyright 2014-2016 Cask Data, Inc.
    :license: Apache License, Version 2.0


    Control the sidebar table-of-contents on pages by settings in the field list at the top of the page:

      :hide-global-toc: true
          This hides the table of contents completely from the left sidebar; default false
    
      :titles-only-global-toc: true
          This puts in the table of contents, but with titles only; no lower-level links; default false
    
      :link-only-global-toc: true
          This puts in the link to the Table of Contents page only; default false; works only if :hide-global-toc: true
#}

{%- set hide_global_toc = false %}
{%- set hide_global_toc_key = 'hide-global-toc' %}

{%- set titles_only_global_toc = false %}
{%- set titles_only_global_toc_key = 'titles-only-global-toc' %}

{%- set link_only_global_toc = false %}
{%- set link_only_global_toc_key = 'link-only-global-toc' %}

{%- if meta is defined %}
    {%- if hide_global_toc_key in meta %}
      {%- set hide_global_toc = meta[hide_global_toc_key] == 'true' %}
    {%- endif %}
    {%- if titles_only_global_toc_key in meta %}
      {%- set titles_only_global_toc = meta[titles_only_global_toc_key] == 'true' %}
    {%- endif %}
    {%- if link_only_global_toc_key in meta %}
      {%- set link_only_global_toc = meta[link_only_global_toc_key] == 'true' %}
    {%- endif %}
{%- endif %}
{%- if not hide_global_toc or link_only_global_toc %}
  {%- if html_short_title_toc|length == 0 %}
    {% set title_br = '' %}
  {%- elif html_short_title_toc|length >= 20 %}
    {% set title_br = ':<br>' %}
  {%- else %}
    {% set title_br = ':' %}
  {%- endif %}
  {%- if pathto(master_doc) == '#' %}
    {% set master_url_root = '' %}{% set doc = '<b>' %}{% set docb = '</b>' %}
  {%- else %}
    {% set master_url_root = master_doc %}{%- set doc = '' %}{% set docb = '' %}
  {% endif %}
  <h3 class="pagenavtitle"><a href="{{ pathto(master_url_root) }}{{ _('/../index.html') }}">{{ html_short_title_toc }}</a></h3>
  {%- if link_only_global_toc %}
    <br>    
  {%- else %}
    <nav class="pagenav">
<!-- 
    <p class="pagenav-toc"><a href="{{ pathto(master_doc) }}">{{ doc }}Table of Contents{{ docb }}</a></p>
 -->
    {{ toctree(titles_only=titles_only_global_toc) }} 
    </nav>
  {%- endif %}
{%- endif %}
